<?php
require_once("myheader.php");
require_once("myfooter.php");
require_once("helper/connexion.php");
require_once("helper/enseignement_helper.php");
myHeader("enseignements");
connexion_sql();
?>
<div class="container">
<div id="body_enseignement">
<h2>Enseignements 
<?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) {
		echo '<button class="btn" onclick="window.location = \'gestion_enseignement.php?action=add\';">
				<i class="icon-plus"></i>
			  </button>';
	  }
?>
</h2>
<div class="accordion" id="accordion">
<?php
$req = getFormation();
$i=0;
while($row = pg_fetch_assoc($req)){
?>
<div class="accordion-group">
  <div class="accordion-heading">
    <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $i; ?>"><?php echo $row["nomformation"]; ?></a> 
    <?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) { ?>
    <a href='#' class="accordion-toggle pull-right" onclick='suppr_formation(<?php echo $row["idformation"]; ?>)'><i class="icon-remove"></i></a>
    <?php } ?>
  </div>
  <div id="collapse<?php echo $i; ?>" class="accordion-body collapse" style="height: 0px">
    <div class="accordion-inner">
         
			  <?php
			  $req2 = getOption( $row["idformation"]);
			  while($rowOption = pg_fetch_assoc($req2)){
			  ?> 
			  <div class="tabbable tabs-left">
				  
				  <ul class="nav nav-tabs">
					<li><h4><?php echo $rowOption['nomoption'];?></h4>
					 <p>Groupes :  <span class="badge badge-info"><?php echo $rowOption['nbgroupestd'];?></span></p>
					 <p>Promotion : <span class="badge badge-warning">8</span></p>
					 <a class="label label-success" href="gestion_option.php?id=<?php echo $rowOption['idoption']; ?>">Modifier</a> 
					 <a class="label label-important" href="#" onclick="suppr_option(<?php echo $rowOption['idoption']; ?>,<?php echo $i; ?>,<?php echo $row["idformation"]; ?>);">Supprimer</a>
					<li>
				  </ul>
				  
			  <div class="tab-content"> 
						   
						  
						 
				  <div id="table_enseignement<?php echo $row["idformation"]; ?>">
							<table class="table table-striped">
							   
							   
							    <thead>
								<tr>
								<th>Enseignement</th>
								<th>Code</th>
								<th>Date Début</th>
								<th>Date Fin</th>
								<?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) {
										echo '<th>Actions</th>';
									  }
								?>	
								</tr>
								</thead>
								<tbody>

									<?php
									  $req3 = getEnseignement($row["idformation"],$rowOption["idoption"]);
									  while($rowEnseignement = pg_fetch_assoc($req3)){
									?>
							    <tr>
								<td><a href="enseignement_detail.php?id=<?php echo $rowEnseignement['id']; ?>&f=<?php echo $row["idformation"]; ?>&o=<?php echo $rowOption["idoption"]; ?> "><?php echo $rowEnseignement['nom']; ?> </a> </td>
								<td><?php echo $rowEnseignement['code']; ?></td>
								<td><?php echo $rowEnseignement['debut']; ?></td>
								<td><?php echo $rowEnseignement['fin']; ?></td>
								
								<?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) {
										echo '<td>
												<a href="gestion_enseignement.php?id='.$rowEnseignement['id'].'&action=edit">
													<i class="icon-pencil"></i>
												</a> 
												<a href="#" class="pull-right" onclick="suppr_enseignement('.$rowEnseignement['id'].','.$row['idformation'].','.$rowOption['idoption'].');">
													<i class="icon-remove"></i>
												</a>
											</td>';
										}
								?>
								</tr>
								<?php }  ?>
								</tbody>
							   

						   </table>
					</div>	  
				   </div>
				   
			   </div>
			   
			<?php } ?>
			
</div>
</div>
</div>
<?php
$i++;
}
?>


<div class="accordion-group">
  <div class="accordion-heading">
    <a class="accordion-toggle" href="charges_detail.php" > Responsabilités Administratives</a> 
    <?php if(isset($_SESSION['id']) && $_SESSION['administrateur']) { ?>
    <a href='#' class="accordion-toggle pull-right" onclick='suppr_formation(<?php echo $row["idformation"]; ?>)'><i class="icon-remove"></i></a>
    <?php } ?>
  </div>
  </div>
</div>
</div>

<?php
	myFooter();
?>
